I'm using multiple if statements in JavaScript? Is there any better way to achieve it through JavaScript?
Better option from multiple statements in JavaScript
369
19-Jul-2021
Updated on 19-Jul-2021
Ethan Karla
20-Jul-2021It should depend on your use of the program. If you are making a program that has a lot of inappropriate conditions then you should go for the if condition. But if your condition depends on some kind of number or some string, you should replace if-else statements with switch case condition, where you have to decide if some 'case' happens, in which block of code is to be executed.
For better understanding switch to the example:
switch(status) {case 'active':
//background green
break;
case 'onhold':
//background yellow
break;
case 'inactive':
//background red
break;
default:
//background grey
break;
}